/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/21
 * Time: 17:15
 */
public class Solution {
    public int search(int[] nums, int target) {
        if(nums[0] > target || nums[nums.length - 1] < target) {
            return -1;
        }
        int mid = nums.length / 2,left = 0, right = nums.length - 1;
        while(left <= right) {
            if(nums[mid] == target) {
                return mid;
            }else if(nums[mid] < target) {
                left = mid + 1;
            }else  {
                 right = mid - 1;
            }
            //mid = (left + right) / 2;
            mid = left + (right - left) / 2;
        }
        return -1;
    }
    public static void main(String[] args) {
        Solution s =  new Solution();
        int ret = s.search(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 10);
        System.out.println(ret);
    }
}